<template>
  <BasicModal v-bind="$attrs" @register="registerModal" :title="t('dictRecycleBin')" :showOkBtn="false" width="1000px" destroyOnClose>
    <BasicTable @register="registerTable">
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
  </BasicModal>
</template>
<script lang="ts" setup>
  // import { ref, toRaw } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { recycleBincolumns } from '../dict.data';
  import { getRecycleBinList, putRecycleBin, deleteRecycleBin } from '../dict.api';
  import { useI18n } from '/@/hooks/web/useI18n';
  const { t } = useI18n('system.dict');
  const { t: common } = useI18n('common');
  // 声明Emits
  const emit = defineEmits(['success', 'register']);
  // const checkedKeys = ref<Array<string | number>>([]);
  const [registerModal] = useModalInner();
  //注册table数据
  const [registerTable, { reload }] = useTable({
    api: getRecycleBinList,
    columns: recycleBincolumns,
    striped: true,
    useSearchForm: false,
    showTableSetting: false,
    clickToRowSelect: false,
    bordered: true,
    showIndexColumn: false,
    pagination: false,
    tableSetting: { fullScreen: true },
    canResize: false,
    actionColumn: {
      width: 140,
      title: common('operateText'),
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: undefined,
    },
  });

  /**
   * 还原事件
   */
  async function handleRevert(record) {
    await putRecycleBin(record.id, reload);
    emit('success');
  }
  /**
   * 删除事件
   */
  async function handleDelete(record) {
    await deleteRecycleBin(record.id, reload);
  }
  /**
   * 批量还原事件
   */
  // function batchHandleRevert() {
  //   handleRevert({ id: toRaw(checkedKeys.value).join(',') });
  // }
  /**
   * 批量删除事件
   */
  // function batchHandleDelete() {
  //   handleDelete({ id: toRaw(checkedKeys.value).join(',') });
  // }
  //获取操作栏事件
  function getTableAction(record): any[] {
    return [
      {
        label: common('restore'),
        icon: 'ant-design:redo-outlined',
        popConfirm: {
          title: common('restoreTip'),
          confirm: handleRevert.bind(null, record),
        },
      },
      {
        label: common('completelyDelete'),
        icon: 'ant-design:scissor-outlined',
        color: 'error',
        popConfirm: {
          title: common('delTips'),
          confirm: handleDelete.bind(null, record),
        },
      },
    ];
  }
</script>
